package com.xpgk.mvc.statistic.daySales;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.user.User;

public class DaySalesStatisticController extends BaseController{
	
	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(DaySalesStatisticController.class);
	
	private DaySalesStatisticService daySalesStatisticService;
	
	
	public void index() {
		String sql = getSqlMy(DaySalesStatisticSQL.sqlId_product);
		setAttr("products", Db.find(sql, Code.lc_ids, Code.proYtLX_ids));
		setAttr("curOrgan", Organization.dao.findById(getCUserOrganIds()));
		render("daySalesStatistic.html");
	}
	
	public void queryDaily(){
		String sql = getSqlMy(DaySalesStatisticSQL.sqlId_product);
		setAttr("products", Db.find(sql, Code.lc_ids, Code.proYtLX_ids));
		Organization  org=Organization.dao.findById(getPara("organids"));
		setAttr("curOrgan", org);
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		setAttr("date", sdf.format(new Date()));
		render("/dlstasticinfo/dailySale.html");
	}
	
	/**
	 * 统计表
	 */
	public void view(){
		String curDate = getPara("curDate", "-1");
		String organIds = getPara("orgianIds", "-1");
		List<Record> result = daySalesStatisticService.getStatisticData(curDate, organIds);
		renderJson(result);
	}
	
	/**
	 * 数据导出
	 */
	public void excel(){
		String curDate = getPara("curDate", "-1");
		String organIds = getPara("organIds", "-1");
		List<Record> result = daySalesStatisticService.getStatisticData(curDate, organIds);
		
		//搜索条件
		Organization  organ=Organization.dao.findById(organIds);
		String search="日期："+curDate+"，门店："+organ.getStr(Organization.column_name)+"，导出人员："+getCUser().getStr(User.column_name);
		
	    render(new DaySalesXLS(result,search, "日销售表"));
	}

}
